package puzzle.projecteuler.p200;

import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang.StringUtils;

public class Problem125B {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		int m = 10000;
		Set<Long> ns = new HashSet<Long>();
		for (int i = 0; i <= m; i ++) {
			for (int j = i+2; j <= m; j ++) {
				long n = ss(j)-ss(i);
				if (n < 100000000) {
					if (isPalindromic(n)) {
						ns.add(n);
					}
				} else {
					break;
				}
			}
		}
		long s = 0;
		for (long a: ns) {
			s += a;
		}
		System.out.println(ns.size());
		System.out.println(s);
	}
	
	public static long ss(int n) {
		return (long)n*(n+1)*(2*n+1)/6;
	}
	
	public static boolean isPalindromic(long n) {
		String a = String.valueOf(n);
		String b = StringUtils.reverse(a);
		return a.equalsIgnoreCase(b);
	}

}
